#ifndef __SECTION_H
#define __SECTION_H


#define SECTION(x)                 __attribute__((section(x)))
#define RT_USED                    __attribute__((used))

#define RT_DEBUG_INIT 	1

typedef void (*init_fn_t)(void);


#if RT_DEBUG_INIT
	struct rt_init_desc
	{
		const char* fn_name;
		const init_fn_t fn;
	};
	
	#define INIT_EXPORT(fn, level)                                                       \
		const char __rti_##fn##_name[] = #fn;                                            \
		RT_USED const struct rt_init_desc __rt_init_desc_##fn SECTION(".rti_fn." level) = \
		{ __rti_##fn##_name, fn};
#else
	#define INIT_EXPORT(fn, level)                                                       \
		RT_USED const init_fn_t __rt_init_##fn SECTION(".rti_fn." level) = fn
#endif

			
#define INIT_BOARD_EXPORT(fn)           INIT_EXPORT(fn, "1")
#define INIT_PREV_EXPORT(fn)            INIT_EXPORT(fn, "2")
#define INIT_DEVICE_EXPORT(fn)          INIT_EXPORT(fn, "3")
#define INIT_COMPONENT_EXPORT(fn)       INIT_EXPORT(fn, "4")
#define INIT_ENV_EXPORT(fn)             INIT_EXPORT(fn, "5")
#define INIT_APP_EXPORT(fn)             INIT_EXPORT(fn, "6")   
		
#define RUN_SEQUENCE(fn)				INIT_EXPORT(fn, "7")    
		
#ifdef __cplusplus
extern "C" {
#endif	
void components_init(void);
void components_run( void );
#ifdef __cplusplus
}
#endif
   
#endif

